package com.itsu.admin.controller;

import com.itsu.admin.model.LoginModel;
import com.itsu.admin.mvc.Result;
import com.itsu.admin.service.AuthService;
import com.itsu.admin.valid.SelectGroup;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author Jerry.Su
 * @Date 2021/12/31 16:49
 */
@RequestMapping("/auth")
@Controller
public class AuthController {

    @Resource
    private AuthService authService;

    @PostMapping("/login")
    @ResponseBody
    public Result login(@Validated(SelectGroup.class) LoginModel model) {
        return authService.auth(model);
    }

    @GetMapping("/logout")
    public String logout() {
        authService.logout();
        return "/login";
    }
}
